using System;
using ACS.Compiler.Tables;
using ACS.Compiler.Tables.Modes;
using ACS.Compiler.Util;

namespace ACS.Compiler.Tree.Impl
{
    public class Plus : Operator
    {
        public override string OperatorToString()
        {
            return "+";
        }

        public override Operators OperatorType
        {
            get { return Operators.Plus; }
        }


        public override string ToString()
        {
            return "+";
        }

        public override void Resolve(string ns, DataTable localData)
        {
            Mode leftMode = Left.ModeResolveExpression(ns, localData, null);
            Mode rigthMode = Right.ModeResolveExpression(ns, localData, null);
            if (!ModesTable.Castable(leftMode, rigthMode))
            {
                Logger.Instance.TraceModesNotEquals(leftMode, rigthMode, this);
            }
            if (! ModesTable.Castable(leftMode, IntMode.Instance) &&
                ! ModesTable.Castable(leftMode, StringMode.Instance) )
            {
                Logger.Instance.TraceWrongMode(leftMode, this);
            }
            _mode = leftMode;
        }
    }
}